package com.rongke.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.mapper.PanicBuyingGoodsMapper;
import com.rongke.model.PanicBuyingGoods;
import com.rongke.model.PanicBuyingGoodsCombineGoods;
import com.rongke.redis.CacheUtil;
import com.rongke.service.PanicBuyingGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @PanicBuyingGoodsServiceImpl
 * @商品抢购ServiceImpl
 * @version : Ver 1.0
 */
@Service
public class PanicBuyingGoodsServiceImpl extends ServiceImpl<PanicBuyingGoodsMapper, PanicBuyingGoods> implements PanicBuyingGoodsService {
    @Autowired
    private PanicBuyingGoodsMapper panicBuyingGoodsMapper;
    @Autowired
    private CacheUtil cacheUtil;
    /**
     * 根据抢购时间获取抢购商品列表
     *
     */
    @Override
    public List<PanicBuyingGoods> selectIndexPanicBuyingGoodsList(Long  pbtId) {
        List<PanicBuyingGoods> pbGoodsList=panicBuyingGoodsMapper.selectIndexPanicBuyingGoodsList(pbtId);
        return pbGoodsList;
    }

    /**
     * 抢购设置提醒 定时执行任务
     * 设定指定任务remindTask在指定时间time执行
     * type 2取消任务1执行任务
     */
    @Override
    public void remindTask(final Long userId, Date startTime,Integer type) {
        Long time = startTime.getTime() - System.currentTimeMillis();
//        final Jedis jedis = new Jedis("127.0.0.1", 6379);

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
//                System.out.println("-------设定要指定任务--------" + userId + "..." + jedis.get(String.valueOf(userId)));
                try {
                    System.out.println("-------设定要指定任务--------" + userId + "..." +cacheUtil.hasKey("aaa"));
//                    System.out.println("-------设定要指定任务--------" + userId + "..." +cacheUtil.get("aaa"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, 3000);// 设定指定的时间time,time毫秒后开始执行


    }

    @Override
    public List<PanicBuyingGoodsCombineGoods> selectLimitedPGListByDurationId(Map map) {
        return panicBuyingGoodsMapper.selectLimitedPGListByDurationId(map);
    }


}



